package cn.bjc.service.impl;

import cn.bjc.domain.Store;
import cn.bjc.mapper.StoreMapper;
import cn.bjc.service.IStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class StoreServiceImpl implements IStoreService {

    @Autowired
    private StoreMapper storeMapper;
    
    @Override
    public Store getById(Long id) {
        return storeMapper.getById(id);
    }

    @Override
    public Store getByProductId(Long product_id) {
        return storeMapper.getByProductId(product_id);
    }

    @Override
    @Transactional
    public Map<String, Object> add(Store store) {
        storeMapper.add(store);
        
        HashMap<String, Object> map = new HashMap<>();
        map.put("success",true);
        map.put("message","添加成功");
        
        return map;
    }

    @Override
    @Transactional
    public Map<String, Object> update(Store store) {
        storeMapper.update(store);

        HashMap<String, Object> map = new HashMap<>();
        map.put("success", true);
        map.put("message", "修改成功");

        return map;
    }


}
